xl: treat sub-command main function like a regular C main() function
authorIan Campbell <ian.campbell@citrix.com>
Tue, 24 Aug 2010 17:30:07 +0000 (18:30 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 24 Aug 2010 17:30:07 +0000 (18:30 +0100)
commite7ebcafdbf8cf285f00ea9e83e827fb1370c3497
tree6d5f64ba34691940fceab9b98ec8a351ddb44853
parent763cad85585b22925912f38f94ed89e18e115920
xl: treat sub-command main function like a regular C main() function

Currently xl passes the entire argc+argv to each subcommand and relies
on the preservation of the global optind variable to ensure that the
subcommand correctly handles argument parsing (e.g. accounting for "xl
[command]" vs "xl -v [command]").

This requirement for individual sub-commands to parse arguments
relative to optind is subtle and prone to being forgotten (or simply
not expected). Several sub-commands have recently been broken in this
way (now fixed).

Therefore arrange that the argv+argc passed to the sub-commands looks
like you would expect for a regular C main function and includes
argv[0] equal to the command name with command specific arguments in
argv[1] onwards.

Since all sub-commands (currently) correctly obey the optind it is
sufficient to reset it to 1 (as described in getopt(3)) in order to
not break the sub-commands' own argument parsing.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/xl.c